<!-- 此版 login 废弃 2024-3-15 16:20:29-->
<template>
<div style="width:100vw; height:100vh;postion:relative;background-color: red;">
    <div class="headers">
        <el-row>
            <el-col :span ="3" style="margin-left:5%;">
                <img style="padding-top:10px;width:70%;" src="../../assets/img/logo.png" alt="">
            </el-col>
            <el-col :span="8">
                <h2> 新绿色药业配方颗粒标准生产质量追溯平台</h2>
            </el-col>
        </el-row>
    </div>
    <div class="login-wrap">
        <div class="ms-login">
            <div class="ms-title">新绿药</div>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px" class="ms-content">
                <el-form-item prop="phone">
                    <el-input v-model.trim="ruleForm.phone" placeholder="员工编号">
                        <el-button slot="prepend" icon="el-icon-user"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                        type="password"
                        placeholder="密码"
                        v-model.trim="ruleForm.password"
                        @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lock"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="num">
                    <el-row :span="24">
                        <el-col :span="14">
                            <el-input v-model.trim="ruleForm.num" auto-complete="off" placeholder="请输入验证码" ></el-input>
                        </el-col>
                        <el-col :span="10">
                            <div class="login-code" @click="init">
                            <!--验证码组件-->
                                <s-identify :identifyCode="identifyCode"></s-identify>
                            </div>
                        </el-col>
                    </el-row>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                </div>
              <div class="login-btn">
                <el-button type="primary" @click="openedit">修改密码</el-button>
              </div>
                <!-- <Geet :isGeet="isgt" @geetPath="GeetPath" @clickChange="GeetChange"></Geet> -->
                <p class="login-tips"></p>
            </el-form>
        </div>
    </div>
  <el-dialog
      title=""
      :visible.sync="centerDialogVisible"
      width="30%"
      center>
    <span>您当前登录账号密码为初始密码，请您尽快更换</span>
    <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="sure">确定</el-button>
    <el-button type="primary" @click="openedit">修改密码</el-button>
  </span>
  </el-dialog>
  <el-dialog
      title=""
      :visible.sync="centerDialogVisible1"
      width="30%"
      center>
<!--    <span>您当前登录账号密码为初始密码，请您尽快更换</span>-->
    <el-form :model="form" :rules = "rules1" ref="form">
      <el-form-item label="" :label-width="formLabelWidth" prop="phone">
        <el-input v-model="form.phone" placeholder="员工编号"  autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="" :label-width="formLabelWidth" prop="oldPassword">
        <el-input v-model="form.oldPassword" placeholder="旧密码" type="password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="" :label-width="formLabelWidth" prop="newPassword">
        <el-input v-model="form.newPassword" placeholder="新密码" type="password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="" :label-width="formLabelWidth" prop="repeatPassword">
        <el-input v-model="form.repeatPassword" placeholder="确认密码" type="password" autocomplete="off"></el-input>
      </el-form-item>
<!--      <span slot="footer" class="dialog-footer">-->
      <el-button type="primary" @click="sure1('form')">确认</el-button>
<!--         </span>-->
    </el-form>

<!--    <el-button type="primary" @click="openedit">修改密码</el-button>-->

  </el-dialog>
    <div class="footer">
        <p>技术支持：三生清源/成都原链</p>
    </div>
</div>

</template>

<script>
import {login,login_verify,login_validate,login_getnum,updatepwd} from '@/request/api'
import SIdentify from '../common/authcode'
export default {
    components: { SIdentify },
	inject: ['reload'],
    data: function() {
        return {
          form: {

          },
          formLabelWidth: '0',
          centerDialogVisible1:false,
          centerDialogVisible:false,
            isgt: false,
            identifyCodes:'z645xcvbnml786kjhfgda453sqerty579uiop12347890',
            identifyCode:'',
            code:'',
            ruleForm: {
                phone: '',
                password: '',
                num:''
            },
            rules: {
                phone: [{ required: true, message: '请输入员工编号', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
                num: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
            },
          rules1: {
            phone: [{ required: true, message: '请输入员工编号', trigger: 'blur' }],
            newPassword: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            oldPassword: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
            repeatPassword: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
          },
        };
    },

    mounted(){
        this.init()
		// if(this.$route.fullPath == "/login"){
		// 	// alert(1111)
		// 	// console.log(localStorage.getItem("reset"))

		// }
        this.$store.commit("setuploadimg","http://" + window.location.host)
        this.$store.commit("setimg","http://" + window.location.host + "/")
    },
    methods: {
      sure1(name){
        this.$refs[name].validate((valid)=>{
          if(valid){
            updatepwd(this.form).then((res)=>{
              this.$notify({
                title: '提示',
                message: '修改成功',
                type: 'success',
                duration:1000
              });
              this.centerDialogVisible1 = false
              this.form = ""
            })
          }else{
            return false
          }
        })
      },
      sure(){
        this.centerDialogVisible = false
        this.$router.push({path:'/home'});
      },
      openedit(){
        this.centerDialogVisible = false
        this.centerDialogVisible1 = true
      },
      open(){
        this.centerDialogVisible = true
      },
        init(){
            login_getnum("").then((res)=>{
                this.identifyCode = res.data
            })
        },
        randomNum (min, max) {
            return Math.floor(Math.random() * (max - min))
        },
        refreshCode () {
            this.identifyCode = ''
            this.makeCode(this.identifyCodes, 4)

        },
        makeCode (o, l) {
            for (let i = 0; i < l; i++) {
                this.identifyCode += this.identifyCodes[
                    this.randomNum(0, 9)
                ]
            }
        },

        submitForm(formName) {
            this.$refs[formName].validate((valid)=>{
				if(valid){
					login({
						phone:this.ruleForm.phone,
						password:this.ruleForm.password,
						num:this.ruleForm.num
					}).then(res=>{

						localStorage.setItem('ms_username', res.data.user.name);
						localStorage.setItem("ide","qqq")
						localStorage.setItem("companyId",res.data.user.companyId)
             localStorage.setItem("userType",res.data.userType)
						localStorage.setItem("userid",res.data.user.id)
						this.$store.commit('setname',res.data.user.name)
						this.$store.commit("setnameid",res.data.user.id)
						this.$store.commit('setpermission',res.data.menus)
            if(res.data.pwAlarm == 1){
              this.centerDialogVisible = true
            }else{
              this.$notify({
                title: '提示',
                message: '登录成功',
                type: 'success',
                duration:1000
              });
              this.$router.push({path:'/home'});
            }

					})
				}else{
					return false
				}
			})
        },
    },
};
</script>


<style scoped>
.footer{
    width:100%;
    height:4vh;
    bottom:20px;
    /* left:50%; */
    position: absolute;
    text-align:center;
    line-height:4vh;
    font-size:14px;
    color:white;
}
.headers{
    width:100%;
    height:8vh;
    top:0;
    left:0;
    position: absolute;
    z-index:9999;
    background:rgba(255, 255, 255, 0.5);
    line-height: 8vh;
}
.el-col{
    margin-top:0;
}
.login-wrap {
    position: relative;
    width: 100%;
    height: 100vh;
    background-image: url(../../assets/img/login-bg2.jpg);
    background-size: 100%;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    border-bottom: 1px solid #ddd;
}
.ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>
